package com.yang.utils;

/**
 * @author: 杨庆
 * @since: 2022.9.7 08:22
 * @description:
 */
import java.io.File;
import java.util.UUID;
public class GenerateFilePath {
    private GenerateFilePath(){}
    public static File getPath(String name){
        // String uuid = UUID.randomUUID().toString();
        String fileNmae = getFileNmae(name);
        int hashCode = name.hashCode();
        String hexString = Integer.toHexString(hashCode);
        char[] chars = hexString.toCharArray();
        String basePath = Constant.BASEPATH;
//        for (char aChar : chars) {
//            basePath = basePath +"/"+aChar;
//        }
        String realPath = basePath+"/"+fileNmae;
        File file = new File(realPath);
        if (!file.getParentFile().exists()) {
            file.getParentFile().mkdirs();
        }
        return file;
    }

    public static String getFileNmae(String name){
        //只要文件的最后的后缀
        int index = name.lastIndexOf(".");
        String substring = name.substring(index);
        String uuid = UUID.randomUUID().toString();
        String filename=uuid+substring;
        return filename;
    }
}

